package net.xo68.destiny.manager.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.xo68.destiny.contract.domain.StringRespondResult;
import net.xo68.destiny.manager.entity.JobDetail;
import net.xo68.destiny.manager.service.JobDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/** 
 * JobDetail controller
 * @author wuxie(16349023@qq.com)
 * @date 2020年12月21日 21:43:52
 *
 */
 @Api(value = "任务管理",tags = {"任务管理"})
@RequestMapping("/JobDetail")
@Slf4j
@RestController
public class JobDetailController{

    @Autowired
    private JobDetailService jobDetailService;

    @ApiOperation(value="详情")
	@GetMapping("/detail/{jobId}")
    public JobDetail detail(@PathVariable(name="jobId") Long jobId) {
        return jobDetailService.find(jobId);
    }
    
    @ApiOperation(value="翻页列表")
    @GetMapping("/list")
    public PageInfo<JobDetail> list(@RequestParam(name="pageIndex",defaultValue="1") int pageIndex,@RequestParam(name="pageSize",defaultValue="10") int pageSize){
        return jobDetailService.list(pageIndex, pageSize);
    }
	
    @ApiOperation(value="创建")
	@PostMapping
    public JobDetail add(@RequestBody JobDetail entity ) {
        return jobDetailService.insert(entity);
    }
	
    @ApiOperation(value="删除")
	@DeleteMapping
	public StringRespondResult delete(@RequestParam(name="id") Long id) {
        int effect=jobDetailService.delete(id);
        if(effect< 1){
            return StringRespondResult.fail();
        }
        return StringRespondResult.ok();
	}
	
    @ApiOperation(value="更新")
	@PutMapping
	public JobDetail update(@RequestBody JobDetail entity) {
	    return jobDetailService.update(entity);
	}
}